#pragma once

#include <iostream>

using namespace std;

class Color3f {
public:
    union {
        struct {
            float r, g, b;
        };
        float e[3];
    };

    /* Constructors.
     */

    //No intialization.
    Color3f();
    Color3f(float r, float g, float b);
    
    /* Math, non-operator.
     */
    float value() const;

    /* Unary operators.
     */
    float operator[](int i) const;

    /* Binary operators with self.
     */
    Color3f operator+(const Color3f& v) const;
    void operator+=(const Color3f& v);
    Color3f operator-(const Color3f& v) const;
    void operator-=(const Color3f& v);

    //Element-wise product.
    Color3f operator*(const Color3f& v) const;
    void operator*=(const Color3f& v);

    /* Binary operators with floats.
     */
    friend Color3f operator*(const Color3f& v, float f);
    friend Color3f operator*(float f, const Color3f& v);
    friend Color3f operator/(const Color3f& v, float f);
    friend Color3f operator/(float f, const Color3f& v);

    void operator*=(float f);
    void operator/=(float f);

    /* Streams.
     */
    friend ostream& operator<<(ostream& os, Color3f& c);
    friend istream& operator>>(istream& is, Color3f& c);
};
